<template>
  <div class="loginbg">
    <div class="loginpage">
      <div class="head">
        <img src="@/assets/logo2.png" alt="">
        <span>探索世界的每一个角落</span>
      </div>
      <div class="content">
        <div class="tab">
          <span :class="{ 'active': isLogin }" @click="changeLogin">登录</span>
          <span :class="{ 'active': !isLogin }" @click="changeRegister">注册</span>
        </div>
        <div class="login" v-if="isLogin">
          <van-form @submit="onLogin">
            <van-cell-group inset>
              <van-field
                v-model="username"
                name="username"
                label="用户名"
                placeholder="用户名"
                :rules="[{ required: true, message: '请填写用户名' }]"
              />
              <van-field
                v-model="password"
                type="password"
                name="password"
                label="密码"
                placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]"
              />
            </van-cell-group>
            <div style="margin: 16px;">
              <van-button round block type="primary" native-type="submit">
                登录
              </van-button>
            </div>
          </van-form>
        </div>
        <div class="register" v-if="!isLogin">
          <van-form @submit="onRegister">
            <van-cell-group inset>
              <van-field
                v-model="username"
                name="username"
                label="用户名"
                placeholder="用户名"
                :rules="[{ required: true, message: '请填写用户名' }]"
              />
              <van-field
                v-model="password"
                type="password"
                name="password"
                label="密码"
                placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]"
              />
              <van-field
                v-model="verifyCode"
                type="text"
                name="verifyCode"
                label="验证码"
                placeholder="验证码"
                :rules="[{ required: true, message: '请填写验证码' }]"
              >
                <template #button>
                  <verifyImg ref="verifyImgRef" />
                </template>
              </van-field>
            </van-cell-group>
            <div style="margin: 16px;">
              <van-button round block type="primary" native-type="submit">
                注册
              </van-button>
            </div>
          </van-form>
        </div>
      </div>
      <div class="quick-login">
        <div class="header">
          <span>快捷登录</span>
        </div>
        <div class="login-style">
          <div class="item" v-for="(item, index) in loginList" :key="index">
            <i :class="`iconfont ${item.img}`" :style="`color: ${item.color};`"></i>
          </div>
        </div>
        <div class="allow">
          <span>登录即表示同意</span>
          <a href="">用户协议</a>
          <span>和</span>
          <a href="">隐私政策</a>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import { ref, reactive } from 'vue'
import verifyImg from '../components/verifyCode.vue';
// 快捷登录方式图标以及对应颜色
const loginList = reactive([
  {
    img: 'icon-weixin',
    color: '#07C160'
  },
  { 
    img: 'icon-QQ',
    color: '#12B7F5'
  },
  {
    img: 'icon-xinlangweibo',
    color: '#E6162D'
  }
])
// 验证码
const verifyImgRef = ref(null)
const verifyCode = ref('');
// 登录注册切换
const isLogin = ref(true)
// 用户名
const username = ref('');
// 密码
const password = ref('');
// 切换登录页面
const changeLogin = () => {
  isLogin.value = true
}
// 切换注册页面
const changeRegister = () => {
  isLogin.value = false
}
</script>

<style lang="less" scoped>
.loginbg{
  background-image: url('@/assets/loginbg2.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: fixed;
  top: 0px;
  width: 100%;
  height: 100%;
  .loginpage{
    height: 100vh;
    background: rgba(255,255,255,0.6);
    .head{
      box-sizing: border-box;
      padding-top: 1.4rem;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      img{
        width: 2.5rem;
        margin: 0 auto;
      }
      span{
        font-weight: 400;
        font-size: 0.37rem;
        color: #4B5563;
        line-height: 20px;
      }
    }
    .content{
      padding:  0.6rem 0.6rem 0.5rem 0.6rem;
      margin: 1rem 0.64rem 0.85rem 0.64rem;
      background: #FFF;
      box-shadow: 0px 10px 15px -3px rgba(0,0,0,0.1), 0px 4px 6px -4px rgba(0,0,0,0.1);
      border-radius: 20px;
      .tab{
        display: flex;
        justify-content: space-around;
        font-weight: 400;
        font-size: 0.37rem;
        color: #9CA3AF;
        span{
          text-align: center;
          flex: 1;
          padding: 8px 0;
          &.active{
            color: #3176FF;
            border-bottom: 1.5px solid #3176FF;
          }
        }
      }
      .van-cell.van-field{
        padding: 10px 0;
        --van-field-label-width: 1.5rem;
      }
    }
    .quick-login{
      padding: 0 0.64rem;
      .header{
        font-weight: 400;
        font-size: 0.37rem;
        color: #6B7280;
        background-color: #fff;
        display: flex;
        align-items: center;
        width: 2.35rem;
        margin: 0 auto;
        span{
          margin: 1px auto;
        }
      }
      .login-style{
        margin-top: 0.64rem;
        display: flex;
        justify-content: space-around;
        .item{
          background-color: #fff;
          border-radius: 999px;
          padding: 0.32rem;
          box-shadow: 0px 4px 6px -1px rgba(0,0,0,0.1), 0px 2px 4px -2px rgba(0,0,0,0.1);
          i{
            margin: auto;
          }
        }
      }
      .allow{
        margin-top: 0.8rem;
        display: flex;
        justify-content: center;
        span{
          font-weight: 400;
          font-size: 0.32rem;
          color: #6B7280;
        }
        a{
          font-weight: 400;
          font-size: 0.32rem;
          color: #3176FF;
          margin: 0 2px;
        }
      }
    }
  }
}

</style>